package com.erp.module.faHuoDanJu.faHuo2

import android.content.Context
import com.erp.bean.CarBean
import com.erp.Interface.OnUserDataInterface
import com.erp.module.faHuoDanJu.AddFaHuoModel
import com.erp.module.faHuoDanJu.FaHuoDanJuContract
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

/**
 * Created by Administrator on 2019/3/18/018.
 * 作者：刘洋
 */
class IFaHuoP2(val context: Context, val KView: FaHuoDanJuContract.FaHuoKView, val carlist : MutableList<CarBean>) : BasePullP(), FaHuoDanJuContract.FaHuoKP {


    val modle : FaHuoDanJuContract.FaHuoMP= AddFaHuoModel()
    var carnumble =""
    var iscarnumble =true
    init {
        PullV =KView
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        modle.getCarShuJu(context, page, pagesize, carnumble,iscarnumble ,onUserDataInterface)
    }

    override fun jsondata(data: String?) {
        try {
            val js = JSONArray(data)
            for(i in 0 until js.length()){
                val jo =js.get(i) as JSONObject
                val bean = CarBean()
                bean.CarNumber = JsonUtil.getvolue(jo,"name")
                bean.car_name = JsonUtil.getvolue(jo,"car_name")
                bean.fullcarload = JsonUtil.getvolue(jo,"fullcarload")
                bean.location = JsonUtil.getvolue(jo,"location")
                carlist.add(bean)
            }
        }catch (e : JSONException){
            e.printStackTrace()
        }
    }

    override fun listClean() {
        carlist.clear()
    }

    override fun getCarNumble(carnumble: String, iscarnumble: Boolean) {
        this.carnumble = carnumble
        this.iscarnumble=iscarnumble
        xiala()
    }
}